package hu.jonas.allunit.views;

import hu.jonas.allunit.AllUnitPlugin;
import hu.jonas.allunit.model.TestResult;
import hu.jonas.allunit.model.TestResultModel;

import org.eclipse.jdt.junit.TestRunListener;
import org.eclipse.jdt.junit.model.ITestCaseElement;

public class AllUnitTestRunListener extends TestRunListener {

	private TestResultModel model;
	
	public AllUnitTestRunListener() {
		this.model = AllUnitPlugin.getTestResultModel();
	}
	
	protected AllUnitTestRunListener(TestResultModel model) {
		this.model = model;
	}
	
	@Override
	public void testCaseFinished(final ITestCaseElement testCaseElement) {
		TestResult testResult = new TestResult(testCaseElement);
		model.add(testResult);
	}
	
	/**
	 * This method should be called before starting to listen test results.
	 * @param numberOfMethods 
	 */
	public void initializeBeforeRunSessions(int numberOfMethods) {
		model.clear();
		model.setTotalTestCount(numberOfMethods);
	}

}
